#include "mypushbutton.h"
#include <QMessageBox>'
#include <QDebug>
//myPushButton::myPushButton(QPushButton *parent) : QPushButton(parent)
//{

//}

myPushButton::myPushButton(QString normalImg, QString pressImg)
{
    this->normalImg = normalImg;
    this->pressImg = pressImg;

    //可复用性,传入图片路径
    QPixmap pix;
    bool ret = pix.load(normalImg);
    if(!ret) {
        QMessageBox::warning(this,"警告","图片加载不成功",QMessageBox::Ok);
        qDebug()<<"按钮图片加载失败\n";
        exit(-1);
    }
    //设置图片固定大小
    this->setFixedSize(pix.width(),pix.height());
    //设置不规则图片样式
    this->setStyleSheet("QPushButton{border:0px;}");
    //设置图标
    this->setIcon(pix);
    //设置图标的大小
    this->setIconSize(QSize(pix.width(),pix.height()));
}

#include <QEasingCurve>
#include <QPropertyAnimation>
//向下
void myPushButton::zoom1()
{
    //创建动态对象
    QPropertyAnimation * animation = new QPropertyAnimation(this,"geometry");
    //设置动画事件间隔
    animation->setDuration(50);
    //起始位置
    animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
    //结束位置  位置靠下,模拟按下效果
    animation->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    //设置弹跳曲线
    animation->setEasingCurve(QEasingCurve::OutBounce);
    //执行动画
    animation->start();
}

//向上
void myPushButton::zoom2()
{
    //创建动态对象
    QPropertyAnimation * animation = new QPropertyAnimation(this,"geometry");
    //设置动画事件间隔
    animation->setDuration(50);
    //起始位置
    animation->setStartValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    //结束位置  位置靠下,模拟弹起效果
    animation->setEndValue(QRect(this->x(),this->y(),this->width(),this->height()));
    //设置弹跳曲线
    animation->setEasingCurve(QEasingCurve::OutBounce);
    //执行动画
    animation->start();
}
